package main 

import (
	"fmt"
	"net"
)


func process(conn net.Conn){

	defer conn.Close() 

	for {

		buf:=make([]byte,1024)

		n,err:=conn.Read(buf)

		if err!=nil{
			fmt.Println("conn read err=",err)
			return
		}
		fmt.Printf("conn recv %v data=%v\n",n,string(buf[:n]))
		
	}
}
func main(){


	listen,err:=net.Listen("tcp","0.0.0.0:12345")

	if err!=nil{
		fmt.Println("err=",err)
		return 
	}
	defer listen.Close()
	for {

		conn,err:=listen.Accept()

		if err!=nil{
			fmt.Printf("accept err=%v\n",err)
		}else{

			fmt.Printf("accept ok conn=%v,ip=%v\n",conn,conn.RemoteAddr().String())
		}

		go process(conn)

	}
	fmt.Println(listen)
}